package com.sockect3d.data;

import struct.StructClass;
import struct.StructField;

/**
 * Created by ming.zhang on 2016/12/8.
 */
@StructClass
public class StructProtocolLogin {
    @StructField(order = 0)
    public byte[] wHeader = new byte[2];                          //开始

    @StructField(order = 1)
    public byte[] unOperatorType = new byte[4];                    //操作类型*

    @StructField(order = 2)
    public byte[] unOperatorCode = new byte[4];                    //操作码*

    @StructField(order = 3)
    public byte[] unPacketSize = new byte[4];                      //包大小，不包括协议头*

    @StructField(order = 4)
    public byte[] xhToken = new byte[8];                       //token*

    @StructField(order = 5)
    public byte[] wPacketSerial = new byte[2];                    //包序列号

    @StructField(order = 6)
    public byte[] wVersion = new byte[2];                         //协议版本

    @StructField(order = 7)
    public byte[] wIsReply  = new byte[2];                        //是否需要构建数据包 0 否，1是

    @StructField(order = 8)
    public byte[] wTail = new byte[2];                            //结束

    public StructProtocolLogin(){
        wHeader = DataUtils.getWordBytes(NetProtocol.HMS_COMMUNICATION_PROTOCOL_MAIN_HEADER);
        wTail = DataUtils.getWordBytes(NetProtocol.HMS_COMMUNICATION_PROTOCOL_MAIN_TAIL);
        wPacketSerial = DataUtils.getWordBytes(0);
        wVersion = DataUtils.getWordBytes(2);
        xhToken = DataUtils.longToBytes(0);
        wIsReply = DataUtils.getWordBytes(1);
    }


    public void setOperatorTypeL(long operatorType){
        unOperatorType = DataUtils.getDwordBytes(operatorType);
    }

    public long getOperatorTypeL(){
        return DataUtils.dwordToLong(unOperatorType);
    }

    public void setOperatorCodeL(long operatorCode){
        unOperatorCode = DataUtils.getDwordBytes(operatorCode);
    }

    public long getOperatorCodeL(){
        return DataUtils.dwordToLong(unOperatorCode);
    }

    public void setPacketSizeI(int packetSize){
        unPacketSize = DataUtils.intToBytes(packetSize);
    }

    public int getPacketSizeI(){
        return DataUtils.bytesToInt(unPacketSize);
    }

    public int getwHeader()
    {
        return DataUtils.wordToInt(wHeader);
    }

    public void setwHeader(byte[] wHeader)
    {
        this.wHeader = wHeader;
    }


}
